package com.sumansoul.calendardemo;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.sumansoul.calendardemo.utils.DateTimeHelper;
import com.sumansoul.calendardemo.utils.TimeSelector;

import java.util.Date;

public class MainActivity extends AppCompatActivity {
    private Button btn;
    private TextView tv_content;
    private String startTime;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        btn = findViewById(R.id.btn);
        tv_content = findViewById(R.id.tv_content);
        initData();
    }

    private void initData() {

        /**
         * 日历弹窗
         */
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                try {
                    //设置日历开始范围
                    TimeSelector.setStartTime("1970-01-01 01:00");
                    //设置日历结束范围
                    TimeSelector.setEndTime("2052-01-01 01:00");
                    //获取对象
                    TimeSelector timeSelector = new TimeSelector(MainActivity.this, new TimeSelector.ResultHandler() {
                            @Override
                            public void handle(String time) {
                                startTime = time;
                                tv_content.setText(time);
                            }
                    }, startTime);
                    //只显示 年月日
                    timeSelector.setMode(TimeSelector.MODE.YMD);
                    //标题设置
                    timeSelector.setTitle("选择日期");
                    timeSelector.setTitleColor(R.color.colorAccent);

                    //取消设置
                    timeSelector.setCancle("取消");
                    timeSelector.setCancleColor(R.color.colorPrimary);

                    //选择设置
                    timeSelector.setNextSelect("选择");
                    timeSelector.setNextSelectColor(R.color.colorAccent);
                    //一定要调用这个显示
                    timeSelector.show();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }
}
